<template>
  <div>
    <el-input
      type="textarea"
      :rows="2"
      placeholder="请输入内容"
      v-model="textarea"
      ref="input"
    >
    </el-input>
    <el-button @click="add">添加</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      textarea: "13123",
    };
  },
  methods: {
    add() {
      let dom = this.$refs.input.$el.childNodes[0];
      console.log(dom);
      let start = dom.selectionStart;
      let end = dom.selectionEnd;
      console.log(start, end);
      console.log(dom.value.substring(0, start));
      console.log(dom.value.substring(end, dom.value.length));
      dom.value =
        dom.value.substring(0, start) +
        "law(x,y)" +
        dom.value.substring(end, dom.value.length);
      dom.selectionStart = 0;
      dom.selectionEnd = 3;
      dom.focus();
    },
  },
};
</script>

<style></style>
